package com.spark.incoicings.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spark.incoicings.dao.DeliveryOrderMapper;
import com.spark.incoicings.dao.OrderDetailMapper;
import com.spark.incoicings.dao.ProductMapper;
import com.spark.incoicings.dao.ShipmentDetailMapper;
import com.spark.incoicings.service.ShipmentDetailService;
import com.spark.invoicings.entity.DeliveryOrder;
import com.spark.invoicings.entity.OrderDetail;
import com.spark.invoicings.entity.Product;
import com.spark.invoicings.entity.ShipmentDetail;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class ShipmentDetailServiceImpl extends
        ServiceImpl<ShipmentDetailMapper, ShipmentDetail> implements ShipmentDetailService {
    @Resource
    private ShipmentDetailMapper shipmentDetailMapper;
    @Resource
    private DeliveryOrderMapper deliveryOrderMapper;
    @Resource
    private ProductMapper productMapper;
    @Resource
    private OrderDetailMapper detailMapper;
    @Override
    public List<ShipmentDetail> selectShipmentDeliveryAll(Map<String, Object> map) {
        List<ShipmentDetail> shipmentDetails = shipmentDetailMapper.selectShipmentDeliveryAll(map);
        shipmentDetails.forEach(shipmentDetail -> {
            DeliveryOrder deliveryOrder = deliveryOrderMapper.selectById(shipmentDetail.getShippingOrderId());
            Product product = productMapper.selectById(shipmentDetail.getProductId());
            OrderDetail orderDetail = detailMapper.selectById(shipmentDetail.getOrderDetailId());
            shipmentDetail.setDeliveryOrder(deliveryOrder);
            shipmentDetail.setProduct(product);
            shipmentDetail.setOrderDetail(orderDetail);
        });
        return shipmentDetails;
    }
}
